﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Bio7
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            var sbh = new SbhNegative();
            var instance = new Instance();
            instance.ReadFile(args[0]);

            while (instance.Oligs.Count != 1)
            {
                var maxLevel = 0;
                var adjacencyMatrix = sbh.CreateAdjacencyMatrixRelative(instance, out maxLevel);
                var v = sbh.CreateAdjacencyList(adjacencyMatrix, maxLevel);

                var solution = sbh.Calc(v);
                var result = instance.GetSolution(solution);

                instance.RemoveSolutionNodes(solution);
                if (result.Count() >= instance.N)
                {
                    result = result.Substring(0, instance.N);
                    instance.Oligs.Insert(0, new Olig(result));
                    break;
                }
                else
                {
                    instance.Oligs.Insert(0, new Olig(result));
                }
            }
            var sol = new List<int>(1) { 0 };
            instance.PrintSolution(sol);
        }
    }
}